﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;

namespace QLKH.PopUp.Hoso
{
    public partial class popSearch : Form
    {
        public popSearch()
        {
            InitializeComponent();
        }

        private void binCombo(ComboBox cb, DataTable dt, string name, string value, string option)
        {
            List<trangthai> list = new List<trangthai>();
            trangthai ls = null;
            ls = new trangthai();
            ls.name = option;
            ls.value = "0";
            list.Add(ls);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ls = new trangthai();
                    ls.name = dt.Rows[i][name].ToString();
                    ls.value = dt.Rows[i][value].ToString();
                    list.Add(ls);
                }
            }
            cb.DataSource = list;
            cb.DisplayMember = "name";
            cb.ValueMember = "value";
        }

        private void popSearch_Load(object sender, EventArgs e)
        {
            //duong
            clDuong d = new clDuong();
            DataTable dtd = d.getdata(1);
            binCombo(cbd, dtd, "tenDuong", "id", "<Chọn đường>");
        }
        // khai báo 1 hàm delegate
        public delegate void SearchCus(string txtsearch,Int16 idd);
        // khai báo 1 kiểu hàm delegate
        public SearchCus MyGetData;

        private void btsearch_Click(object sender, EventArgs e)
        {
            if (MyGetData != null)
            {

                MyGetData(Querys.LocDau(txtsearch.Text.Trim()).ToLower(), ((cbd.SelectedValue == null) ? Int16.Parse("0") : Int16.Parse(cbd.SelectedValue.ToString().Trim())));
            }
            this.Close();
        }

        private void btquit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
